package com.example.administrator.foodrowfresh.superBase;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lqr on 2016/4/30.
 */
public abstract class MyBaseFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView=initView();
        return rootView;
    }

    public abstract View initView();
    public abstract void initData();
    public  void getData(String path, final MyBaseCallBack callBack) {
        RequestParams params=new RequestParams(path);
        callBack.onStart();
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                callBack.onResult(result);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                callBack.onError();
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                callBack.onFinish();
            }
        });

    }
}
